<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a normalized query trace log for each query inspected by the query cache</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysqlnd-qc-get-normalized-query-trace-log" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqlnd_qc_get_normalized_query_trace_log</h1>
  <p class="verinfo">(PECL mysqlnd_qc &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">mysqlnd_qc_get_normalized_query_trace_log</span> &mdash; <span class="dc-title">Returns a normalized query trace log for each query inspected by the query cache</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mysqlnd-qc-get-normalized-query-trace-log-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   
   <span class="methodname"><strong>mysqlnd_qc_get_normalized_query_trace_log</strong></span>
    ( <span class="methodparam">void</span>
   ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
   Returns a normalized query trace log for each query inspected by the query cache.
   The collection of the trace log is disabled by default. To collect
   the trace log you have to set the PHP configuration directive
   <em>mysqlnd_qc.collect_normalized_query_trace</em> to
   <em>1</em>
  </p>
  <p class="para">
   Entries in the trace log are grouped by the normalized query statement.
   The normalized query statement is the query statement with all statement
   parameter values being replaced with a question mark. For example, the two
   statements <em>SELECT id FROM test WHERE id = 1</em> and
   <em>SELECT id FROM test WHERE id = 2</em> are normalized as
   <em>SELECT id FROM test WHERE id = ?</em>. Whenever a statement
   is inspected by the query cache which matches the normalized statement pattern,
   its statistics are grouped by the normalized statement string.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysqlnd-qc-get-normalized-query-trace-log-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysqlnd-qc-get-normalized-query-trace-log-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An array of query log. Every list entry contains
   the normalized query stringand further detail information.
  </p>

  <table class="doctable informaltable">
   
    <col width="1*" />
    <col width="9*" />
    <thead>
     <tr>
      <th>Key</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>
       <em>query</em>
      </td>
      <td>
       Normalized statement string.
      </td>
     </tr>

     <tr>
      <td>
       <em>occurences</em>
      </td>
      <td>
       How many statements have matched the normalized statement
       string in addition to the one which has created the log entry.
       The value is zero if a statement has been normalized, its normalized
       representation has been added to the log but no further queries inspected
       by PECL/mysqlnd_qc have the same normalized statement string.
      </td>
     </tr>

     <tr>
      <td>
       <em>eligible_for_caching</em>
      </td>
      <td>
       Whether the statement could be cached. An statement eligible for
       caching has not necessarily been cached. It not possible to tell
       for sure if or how many cached statement have contributed to the
       aggregated normalized statement log entry. However, comparing
       the minimum and average run time one can make an educated guess.
      </td>
     </tr>

     <tr>
      <td>
       <em>avg_run_time</em>
      </td>
      <td>
       The average run time of all queries contributing to the
       query log entry. The run time is the time between sending the
       query statement to MySQL and receiving an answer from MySQL.
      </td>
     </tr>

     <tr>
      <td>
       <em>avg_store_time</em>
      </td>
      <td>
       The average store time of all queries contributing to the
       query log entry. The store time is the time needed to fetch
       a statements result set from the server to the client and,
       storing it on the client.
      </td>
     </tr>

     <tr>
      <td>
       <em>min_run_time</em>
      </td>
      <td>
       The minimum run time of all queries contributing to the
       query log entry.
      </td>
     </tr>

     <tr>
      <td>
       <em>min_store_time</em>
      </td>
      <td>
       The minimum store time of all queries contributing to the
       query log entry.
      </td>
     </tr>

     <tr>
      <td>
       <em>max_run_time</em>
      </td>
      <td>
       The maximum run time of all queries contributing to the
       query log entry.
      </td>
     </tr>

     <tr>
      <td>
       <em>max_store_time</em>
      </td>
      <td>
       The maximum store time of all queries contributing to the
       query log entry.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>



 <div class="refsect1 examples" id="refsect1-function.mysqlnd-qc-get-normalized-query-trace-log-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2297">
   <p><strong>Example #1 <span class="function"><strong>mysqlnd_qc_get_normalized_query_trace_log()</strong></span> example</strong></p>
  <div class="example-contents">
<div class="inicode"><pre class="inicode">mysqlnd_qc.collect_normalized_query_trace=1</pre>
</div>
   </div>

   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Connect,&nbsp;create&nbsp;and&nbsp;populate&nbsp;test&nbsp;table&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"host"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"schema"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"port"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"socket"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;IF&nbsp;EXISTS&nbsp;test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;test(id&nbsp;INT)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;test(id)&nbsp;VALUES&nbsp;(1),&nbsp;(2)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;not&nbsp;cached&nbsp;*/<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id&nbsp;FROM&nbsp;test&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;cache&nbsp;put&nbsp;*/<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"/*"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">MYSQLND_QC_ENABLE_SWITCH&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"*/"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id&nbsp;FROM&nbsp;test&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;2"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;cache&nbsp;hit&nbsp;*/<br /></span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"/*"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">MYSQLND_QC_ENABLE_SWITCH&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"*/"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id&nbsp;FROM&nbsp;test&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;2"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">mysqlnd_qc_get_normalized_query_trace_log</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
array(1) {
  [&quot;id&quot;]=&gt;
  string(1) &quot;1&quot;
}
array(1) {
  [&quot;id&quot;]=&gt;
  string(1) &quot;2&quot;
}
array(1) {
  [&quot;id&quot;]=&gt;
  string(1) &quot;2&quot;
}
array(4) {
  [0]=&gt;
  array(9) {
    [&quot;query&quot;]=&gt;
    string(25) &quot;DROP TABLE IF EXISTS test&quot;
    [&quot;occurences&quot;]=&gt;
    int(0)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(false)
    [&quot;avg_run_time&quot;]=&gt;
    int(0)
    [&quot;min_run_time&quot;]=&gt;
    int(0)
    [&quot;max_run_time&quot;]=&gt;
    int(0)
    [&quot;avg_store_time&quot;]=&gt;
    int(0)
    [&quot;min_store_time&quot;]=&gt;
    int(0)
    [&quot;max_store_time&quot;]=&gt;
    int(0)
  }
  [1]=&gt;
  array(9) {
    [&quot;query&quot;]=&gt;
    string(27) &quot;CREATE TABLE test (id INT )&quot;
    [&quot;occurences&quot;]=&gt;
    int(0)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(false)
    [&quot;avg_run_time&quot;]=&gt;
    int(0)
    [&quot;min_run_time&quot;]=&gt;
    int(0)
    [&quot;max_run_time&quot;]=&gt;
    int(0)
    [&quot;avg_store_time&quot;]=&gt;
    int(0)
    [&quot;min_store_time&quot;]=&gt;
    int(0)
    [&quot;max_store_time&quot;]=&gt;
    int(0)
  }
  [2]=&gt;
  array(9) {
    [&quot;query&quot;]=&gt;
    string(40) &quot;INSERT INTO test (id ) VALUES (? ), (? )&quot;
    [&quot;occurences&quot;]=&gt;
    int(0)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(false)
    [&quot;avg_run_time&quot;]=&gt;
    int(0)
    [&quot;min_run_time&quot;]=&gt;
    int(0)
    [&quot;max_run_time&quot;]=&gt;
    int(0)
    [&quot;avg_store_time&quot;]=&gt;
    int(0)
    [&quot;min_store_time&quot;]=&gt;
    int(0)
    [&quot;max_store_time&quot;]=&gt;
    int(0)
  }
  [3]=&gt;
  array(9) {
    [&quot;query&quot;]=&gt;
    string(31) &quot;SELECT id FROM test WHERE id =?&quot;
    [&quot;occurences&quot;]=&gt;
    int(2)
    [&quot;eligible_for_caching&quot;]=&gt;
    bool(true)
    [&quot;avg_run_time&quot;]=&gt;
    int(159)
    [&quot;min_run_time&quot;]=&gt;
    int(12)
    [&quot;max_run_time&quot;]=&gt;
    int(307)
    [&quot;avg_store_time&quot;]=&gt;
    int(10)
    [&quot;min_store_time&quot;]=&gt;
    int(8)
    [&quot;max_store_time&quot;]=&gt;
    int(13)
  }
}
</pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysqlnd-qc-get-normalized-query-trace-log-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <a href="mysqlnd_qc.configuration.html" class="link">Runtime configuration</a>
    </li>
    <li class="member">
     <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.collect-query-trace" class="link">mysqlnd_qc.collect_normalized_query_trace</a>
    </li>
    <li class="member">
     <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.time-statistics" class="link">mysqlnd_qc.time_statistics</a>
    </li>
    <li class="member">
     <span class="function"><a href="mysqlnd_qc_get_query_trace_log.html" class="function" rel="rdfs-seeAlso">mysqlnd_qc_get_query_trace_log()</a> - Returns a backtrace for each query inspected by the query cache</span>
    </li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>